using System;
using System.Collections.Generic;
using System.Text;

namespace DNNToolkit.Modules.CityTaxLocator.Components
{
    public class CityItem
    {
        private readonly string mStateName;
        protected internal CityItem(string line1,
            string line2,
            string line3,
            string stateName)
        {
            mLine1 = line1;
            mLine2 = line2;
            mLine3 = line3;
            mStateName = stateName;
        }

        #region instance variables
        private string mLine1;
        private string mLine2;
        private string mLine3;
        #endregion


        #region column values
        public string State
        {
            get {
                return mStateName;
            }
        }


        public string LocalName
        {
            get {
                return  GetValue(mLine1, 4, 43);
            }
        }


        public string LocRate
        {
            get {
                return GetValue(mLine2, 64, 8);
            }
        }


        public string SchlRate
        {
            get {
                return GetValue(mLine2, 75, 9);
            }
        }


        public string WhRate
        {
            get {
                return GetValue(mLine2, 88, 8);
            }
        }


        public string W2Name
        {
            get {
                return GetValue(mLine2, 100, 16);
            }
        }


        public string LocalCD
        {
            get {
                return GetValue(mLine3, 11, 9);
            }
        }


        public string ResInd
        {
            get {
                return GetValue(mLine3, 21, 8);
            }
        }


        public string CountyName
        {
            get {
                return GetValue(mLine3, 30, 18);
            }
        }


        public string AdditionalJur
        {
            get {
                return GetValue(mLine3, 48, 44);
            }
        }


        public string Comments
        {
            get {
                return GetValue(mLine3, 93, 50);
            }
        }
        #endregion


        private string GetValue(string line, long startPos, long length)
        {
            if (startPos >= line.Length - 1)
                return null;
            string retValue = line.Substring((int)startPos, (int)(startPos + length > line.Length ? line.Length - startPos : length));

            retValue = retValue.TrimStart(" ".ToCharArray());

            return retValue.TrimEnd(" ".ToCharArray());
        }
    }
}
